fix(agent): evict persistence-backed session caches#2339
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
LGTM. Changes look good.
Automated review by github-manager-bot
|
This PR has conflicts with the base branch and cannot be merged. Please rebase or merge the base branch into your branch and resolve the conflicts: git fetch origin
git checkout agent/fix-state-cache-eviction
git rebase origin/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved. Automated notification by github-manager-bot |
|
@oss-maintainer The merge conflict has been resolved, and the CI formatting issue has also been fixed. Could you please re-review the PR when you have a chance? Thanks! |
oss-maintainer
left a comment
There was a problem hiding this comment.
LGTM. Looks good.
Automated review by "github-manager-bot"
AgentScope-Java Version
2.0.1-SNAPSHOT
Summary
Root cause
When an
AgentStateStorewas configured, every session was loaded intostateCacheandpermissionEngineCache, but completed calls never removed those entries. Long-running multi-user services therefore retained one cache entry per observed session indefinitely. Cleanup also could not safely rely on shared agent fields because concurrent calls may have advanced them to a different session.Implementation
AgentBasenow exposes a terminal callback tied to the exact call scope returned bybeforeAgentExecution.ReActAgentuses that scope to conditionally remove only the state and permission-engine instances owned by the completed call. Conditional map removal prevents an older call from evicting a newer replacement for the same slot.The new
evictSessionandevictUsermethods provide explicit host-controlled cleanup, whileclose()clears both caches. Persistence is not deleted; subsequent access reloads state from the configured store.Verification
mvn test(local macOS runner used headless AWT and a preloaded Mockito agent)agentscope-core: 2,222 tests passed, 9 skippedFixes #2261